public class Solution2221 {
    public int triangularSum(int[] nums) {
        int n=nums.length;
        for (int i=n-2;i>=0;i--){
            int[] f=new int[i+1];
            for (int j=0;j<=i;j++){
                f[j]=(nums[j]+nums[j+1])%10;
            }
            nums=f;
        }
        return nums[0];
    }

    public static void main(String[] args) {
        System.out.println(new Solution2221().triangularSum(new int[]{1,2,3,4,5}));
    }
}
